package com.esri.core.geometry;

import com.github.mikephil.charting.utils.Utils;

/* loaded from: classes.dex */
final class Transformation3D {
    public double xd;
    public double xx;
    public double xy;
    public double xz;
    public double yd;
    public double yx;
    public double yy;
    public double yz;
    public double zd;
    public double zx;
    public double zy;
    public double zz;

    public void setZero() {
        this.xx = Utils.DOUBLE_EPSILON;
        this.yx = Utils.DOUBLE_EPSILON;
        this.zx = Utils.DOUBLE_EPSILON;
        this.xy = Utils.DOUBLE_EPSILON;
        this.yy = Utils.DOUBLE_EPSILON;
        this.zy = Utils.DOUBLE_EPSILON;
        this.xz = Utils.DOUBLE_EPSILON;
        this.yz = Utils.DOUBLE_EPSILON;
        this.zz = Utils.DOUBLE_EPSILON;
        this.xd = Utils.DOUBLE_EPSILON;
        this.yd = Utils.DOUBLE_EPSILON;
        this.zd = Utils.DOUBLE_EPSILON;
    }

    public void setScale(double d, double d2, double d3) {
        this.xx = d;
        this.yx = Utils.DOUBLE_EPSILON;
        this.zx = Utils.DOUBLE_EPSILON;
        this.xy = Utils.DOUBLE_EPSILON;
        this.yy = d2;
        this.zy = Utils.DOUBLE_EPSILON;
        this.xz = Utils.DOUBLE_EPSILON;
        this.yz = Utils.DOUBLE_EPSILON;
        this.zz = d3;
        this.xd = Utils.DOUBLE_EPSILON;
        this.yd = Utils.DOUBLE_EPSILON;
        this.zd = Utils.DOUBLE_EPSILON;
    }

    public void setTranslate(double d, double d2, double d3) {
        this.xx = 1.0d;
        this.yx = Utils.DOUBLE_EPSILON;
        this.zx = Utils.DOUBLE_EPSILON;
        this.xy = Utils.DOUBLE_EPSILON;
        this.yy = 1.0d;
        this.zy = Utils.DOUBLE_EPSILON;
        this.xz = Utils.DOUBLE_EPSILON;
        this.yz = Utils.DOUBLE_EPSILON;
        this.zz = 1.0d;
        this.xd = d;
        this.yd = d2;
        this.zd = d3;
    }

    public void translate(double d, double d2, double d3) {
        this.xd += d;
        this.yd += d2;
        this.zd += d3;
    }

    public Envelope3D transform(Envelope3D envelope3D) {
        if (envelope3D.isEmpty()) {
            return envelope3D;
        }
        Point3D[] point3DArr = new Point3D[8];
        envelope3D.queryCorners(point3DArr);
        a(point3DArr, 8, point3DArr);
        envelope3D.setFromPoints(point3DArr);
        return envelope3D;
    }

    void a(Point3D[] point3DArr, int i, Point3D[] point3DArr2) {
        for (int i2 = 0; i2 < i; i2++) {
            Point3D point3D = new Point3D();
            Point3D point3D2 = point3DArr[i2];
            point3D.x = (this.xx * point3D2.x) + (this.xy * point3D2.y) + (this.xz * point3D2.z) + this.xd;
            point3D.y = (this.yx * point3D2.x) + (this.yy * point3D2.y) + (this.yz * point3D2.z) + this.yd;
            point3D.z = (this.zx * point3D2.x) + (this.zy * point3D2.y) + (this.zz * point3D2.z) + this.zd;
            point3DArr2[i2] = point3D;
        }
    }

    public Point3D transform(Point3D point3D) {
        Point3D point3D2 = new Point3D();
        point3D2.x = (this.xx * point3D.x) + (this.xy * point3D.y) + (this.xz * point3D.z) + this.xd;
        point3D2.y = (this.yx * point3D.x) + (this.yy * point3D.y) + (this.yz * point3D.z) + this.yd;
        point3D2.z = (this.zx * point3D.x) + (this.zy * point3D.y) + (this.zz * point3D.z) + this.zd;
        return point3D2;
    }

    public void transform(Point3D[] point3DArr, int i, int i2) {
        int min = Math.min(point3DArr.length, i2 + i);
        while (i < min) {
            Point3D point3D = new Point3D();
            Point3D point3D2 = point3DArr[i];
            point3D.x = (this.xx * point3D2.x) + (this.xy * point3D2.y) + (this.xz * point3D2.z) + this.xd;
            point3D.y = (this.yx * point3D2.x) + (this.yy * point3D2.y) + (this.yz * point3D2.z) + this.yd;
            point3D.z = (this.zx * point3D2.x) + (this.zy * point3D2.y) + (this.zz * point3D2.z) + this.zd;
            point3DArr[i] = point3D;
            i++;
        }
    }

    public void mul(Transformation3D transformation3D) {
        multiply(this, transformation3D, this);
    }

    public void mulLeft(Transformation3D transformation3D) {
        multiply(transformation3D, this, this);
    }

    public void multiply(Transformation3D transformation3D, Transformation3D transformation3D2, Transformation3D transformation3D3) {
        double d = transformation3D.xx;
        double d2 = transformation3D2.xx;
        double d3 = transformation3D.yx;
        double d4 = transformation3D2.xy;
        double d5 = (d * d2) + (d3 * d4);
        double d6 = transformation3D.zx;
        double d7 = transformation3D2.xz;
        double d8 = d5 + (d6 * d7);
        double d9 = transformation3D2.yx;
        double d10 = d * d9;
        double d11 = transformation3D2.yy;
        double d12 = transformation3D2.yz;
        double d13 = transformation3D2.zx;
        double d14 = d * d13;
        double d15 = transformation3D2.zy;
        double d16 = d14 + (d3 * d15);
        double d17 = transformation3D2.zz;
        double d18 = d16 + (d6 * d17);
        double d19 = transformation3D.xy;
        double d20 = transformation3D.yy;
        double d21 = transformation3D.zy;
        double d22 = (d19 * d2) + (d20 * d4) + (d21 * d7);
        double d23 = (d19 * d9) + (d20 * d11) + (d21 * d12);
        double d24 = (d19 * d13) + (d20 * d15) + (d21 * d17);
        double d25 = transformation3D.xz;
        double d26 = transformation3D.yz;
        double d27 = transformation3D.zz;
        double d28 = (d25 * d2) + (d26 * d4) + (d27 * d7);
        double d29 = (d25 * d13) + (d26 * d15) + (d27 * d17);
        double d30 = transformation3D.xd;
        double d31 = transformation3D.yd;
        double d32 = transformation3D.zd;
        double d33 = (d2 * d30) + (d4 * d31) + (d7 * d32) + transformation3D2.xd;
        transformation3D3.xx = d8;
        transformation3D3.yx = d10 + (d3 * d11) + (d6 * d12);
        transformation3D3.zx = d18;
        transformation3D3.xy = d22;
        transformation3D3.yy = d23;
        transformation3D3.zy = d24;
        transformation3D3.xz = d28;
        transformation3D3.yz = (d25 * d9) + (d26 * d11) + (d27 * d12);
        transformation3D3.zz = d29;
        transformation3D3.xd = d33;
        transformation3D3.yd = (d30 * d9) + (d31 * d11) + (d32 * d12) + transformation3D2.yd;
        transformation3D3.zd = (d30 * d13) + (d31 * d15) + (d32 * d17) + transformation3D2.zd;
    }

    public void inverse(Transformation3D transformation3D, Transformation3D transformation3D2) {
        double d = transformation3D.xx;
        double d2 = transformation3D.yy;
        double d3 = transformation3D.zz;
        double d4 = transformation3D.zy;
        double d5 = transformation3D.yz;
        double d6 = transformation3D.yx;
        double d7 = transformation3D.xy;
        double d8 = d7 * d3;
        double d9 = transformation3D.xz;
        double d10 = transformation3D.zx;
        double d11 = ((((d2 * d3) - (d4 * d5)) * d) - ((d8 - (d4 * d9)) * d6)) + (((d7 * d5) - (d2 * d9)) * d10);
        if (d11 != Utils.DOUBLE_EPSILON) {
            double d12 = 1.0d / d11;
            double d13 = ((d2 * d3) - (d4 * d5)) * d12;
            double d14 = (-((d7 * d3) - (d4 * d9))) * d12;
            double d15 = ((d7 * d5) - (d2 * d9)) * d12;
            double d16 = (-((d6 * d3) - (d5 * d10))) * d12;
            double d17 = ((d3 * d) - (d10 * d9)) * d12;
            double d18 = (-((d5 * d) - (d9 * d6))) * d12;
            double d19 = ((d6 * d4) - (d10 * d2)) * d12;
            double d20 = (-((d4 * d) - (d10 * d7))) * d12;
            double d21 = ((d * d2) - (d6 * d7)) * d12;
            double d22 = transformation3D.xd;
            double d23 = transformation3D.yd;
            double d24 = transformation3D.zd;
            transformation3D2.xx = d13;
            transformation3D2.yx = d16;
            transformation3D2.zx = d19;
            transformation3D2.xy = d14;
            transformation3D2.yy = d17;
            transformation3D2.zy = d20;
            transformation3D2.xz = d15;
            transformation3D2.yz = d18;
            transformation3D2.zz = d21;
            transformation3D2.xd = -((d22 * d13) + (d23 * d14) + (d24 * d15));
            transformation3D2.yd = -((d22 * d16) + (d23 * d17) + (d24 * d18));
            transformation3D2.zd = -((d22 * d19) + (d23 * d20) + (d24 * d21));
            return;
        }
        throw new GeometryException("math singularity");
    }

    public Transformation3D copy() {
        Transformation3D transformation3D = new Transformation3D();
        transformation3D.xx = this.xx;
        transformation3D.yx = this.yx;
        transformation3D.zx = this.zx;
        transformation3D.xy = this.xy;
        transformation3D.yy = this.yy;
        transformation3D.zy = this.zy;
        transformation3D.xz = this.xz;
        transformation3D.yz = this.yz;
        transformation3D.zz = this.zz;
        transformation3D.xd = this.xd;
        transformation3D.yd = this.yd;
        transformation3D.zd = this.zd;
        return transformation3D;
    }
}
